package com.tjdr.his.drugstore.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tjdr.his.common.result.HttpResp;
import com.tjdr.his.common.result.ResultCode;
import com.tjdr.his.domain.entity.Register;
import com.tjdr.his.drugstore.service.IRegisterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @AUTHOR 张三
 * @DATE 2024/10/10 14:49
 * @DESCRIBER
 */
@RestController
@RequestMapping("/api/register")
@CrossOrigin
@Slf4j
public class RegisterController {
    @Autowired
    private IRegisterService service;
    /**
     *
     * @param
     * @param
     * @return 病人信息
     */
    @GetMapping("getRegisterInfo")
    public HttpResp getRegisterInfo(String realName,String caseNumber,int pageSize,int currentPage){
        log.debug("getRegisterInfo{},{},{},{}",realName,caseNumber,pageSize,currentPage);
        //调用业务层
        IPage page = service.getRegisterByCondtion(realName,caseNumber,pageSize,currentPage);
        Map map = new HashMap();
        map.put("total",page.getTotal());
        map.put("list",page.getRecords());
        HttpResp httpResp = new HttpResp<>(ResultCode.OPTION_SUCCESS,new Date(),map);
        log.debug("httpResp:{}",httpResp);
        return httpResp;

    }

    @DeleteMapping("removeRegisterByCaseNumber")
    public HttpResp removeRegisterByCaseNumber(String caseNumber){
        log.debug("caseNumber:{}",caseNumber);
        boolean result = service.deleteRegisterByCaseNumber(caseNumber);
        HttpResp httpResp = new HttpResp(ResultCode.OPTION_SUCCESS,new Date(),result);
        log.debug("httpResp:{}",httpResp);
        return httpResp;
    }

    @GetMapping("getPrescriptionById/{id}/{pageSize}/{page}")
    public HttpResp getRegisterPresDrug(@PathVariable int id, @PathVariable int pageSize, @PathVariable(name = "page") int currentPage,@RequestParam(required = false,defaultValue = "已缴费") String drugState){
        log.debug("getPrescriptionById:{},{},{}",id,pageSize,currentPage);
        IPage page = service.getRegisterPresDrug(id,pageSize,currentPage,drugState);
        Map<String,Object> map = new HashMap();
        map.put("total",page.getTotal());
        map.put("list",page.getRecords());
        HttpResp httpResp = new HttpResp<>(ResultCode.OPTION_SUCCESS,new Date(),map);
        log.debug("httpResp:{}",httpResp);
        return httpResp;
    }

}
